function varargout = vslice(varargin)
% VSLICE M-file for vslice.fig
%      VSLICE, by itself, creates a new VSLICE or raises the existing
%      singleton*.
%
%      H = VSLICE returns the handle to a new VSLICE or the handle to
%      the existing singleton*.
%
%      VSLICE('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in VSLICE.M with the given input arguments.
%
%      VSLICE('Property','Value',...) creates a new VSLICE or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before vslice_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to vslice_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help vslice

% Last Modified by GUIDE v2.5 22-Sep-2006 11:49:49

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @vslice_OpeningFcn, ...
                   'gui_OutputFcn',  @vslice_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before vslice is made visible.
function vslice_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to vslice (see VARARGIN)

% Choose default command line output for vslice
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes vslice wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = vslice_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --------------------------------------------------------------------
function vslice_export_to_ws_menu_Callback(hObject, eventdata, handles)
% hObject    handle to vslice_export_to_ws_menu (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
%
% Export the vslice data into the base workspace.

	vdata = guidata ( hObject );
	gdata = guidata ( vdata.parent );
	assignin ( 'base', 'x', gdata.vslice_data.vx );
	assignin ( 'base', 'z', gdata.vslice_data.vz );
	assignin ( 'base', 'data', gdata.vslice_data.vdata );
	assignin ( 'base', 'cpx', gdata.vslice_data.control_pt_x );
	assignin ( 'base', 'cpy', gdata.vslice_data.control_pt_y );


% --------------------------------------------------------------------
function vslice_file_menu_Callback(hObject, eventdata, handles)
% hObject    handle to vslice_file_menu (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --------------------------------------------------------------------
function vslice_velocity_menu_Callback(hObject, eventdata, handles)
% hObject    handle to vslice_velocity_menu (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

	vdata = guidata ( hObject );

	vslice_options.use_vslice_line = 1;
	rslice_vslice_velocity_redraw( vdata.parent, vslice_options )

% --------------------------------------------------------------------
function Untitled_1_Callback(hObject, eventdata, handles)
% hObject    handle to Untitled_1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --------------------------------------------------------------------
function Print_vslice_tag_Callback(hObject, eventdata, handles)
% hObject    handle to Print_vslice_tag (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

	printdlg;


% --------------------------------------------------------------------
function Vslice_hide_tag_Callback(hObject, eventdata, handles)
% hObject    handle to Vslice_hide_tag (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
%
% Don't destroy the vslice figure, just hide it.  This disables 
% redraws.


	vdata = guidata ( hObject );
	gdata = guidata ( vdata.parent );

	%
	% Is the vslice figure visible?  If so, then issue a redraw.
	vis = get ( gdata.vslice_figure, 'Visible' );
	if strcmp ( vis, 'on' )
		set ( gdata.vslice_figure, 'Visible', 'off' );
	end

	return


% --------------------------------------------------------------------
function vslice_autoscale_clim_Callback(hObject, eventdata, handles)
% hObject    handle to vslice_autoscale_clim (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

	vdata = guidata ( hObject );

    if ~isfield ( vdata, 'autoscale' )
        vdata.autoscale = 0;
    end


    if vdata.autoscale == 0
        %
        % Turn autoscaling on.
        vdata.autoscale = 1;

        %
        % Change the label so that the next time we are turning it off.
        set ( gcbo, 'Label', 'Disable Autoscale' );

    else
        %
        % Turn autoscaling off.
        vdata.autoscale = 0;

        %
        % Change the label so that the next time we are turning it on.
        set ( gcbo, 'Label', 'Enable Autoscale' );

    end

    guidata(hObject, vdata );

    rslice_vslice_redraw(vdata.parent);

